/* SPDX-License-Identifier: GPL-2.0 */
#ifndef UTILS_PFN_H
#define UTILS_PFN_H

#ifndef __ASSEMBLY__

#include <utils/types.h>
#include <utils/pagesize.h>

#define PFN_ALIGN(x)	(((unsigned long)(x) + (UTILS_PAGE_SIZE - 1)) & UTILS_PAGE_MASK)
#define PFN_UP(x)	(((x) + UTILS_PAGE_SIZE-1) >> UTILS_PAGE_SHIFT)
#define PFN_DOWN(x)	((x) >> UTILS_PAGE_SHIFT)
#define PFN_PHYS(x)	((phys_addr_t)(x) << UTILS_PAGE_SHIFT)
#define PHYS_PFN(x)	((unsigned long)((x) >> UTILS_PAGE_SHIFT))

/*
 * Convert a physical address to a Page Frame Number and back
 */
#define	__phys_to_pfn(paddr)	PHYS_PFN(paddr)
#define	__pfn_to_phys(pfn)	PFN_PHYS(pfn)

#endif /* !__ASSEMBLY__ */
#endif /* !UTILS_PFN_H */
